package com.jackchong.utils;

import android.app.Activity;
import android.app.Dialog;
import android.view.Gravity;
import android.view.Window;

public class DialogUtil {

    /**
     * 控制dialog显示or隐藏
     *
     * @param mDialog
     * @param activity
     * @param show
     */
    public static void controlDialogShow(Dialog mDialog, Activity activity, boolean show) {
        if (activity == null) {
            return;
        }
        try {
            if (!activity.isFinishing() && mDialog != null) {
                if (show) {
                    if (ActivityUtils.isForeground(activity)) {
                        if (!mDialog.isShowing()) {
                            mDialog.show();
                        }
                    }
                } else {
                    mDialog.dismiss();
                }
            }
        }catch (Exception e){
        }
    }

    public static void colseSomeDialog(Activity activity, Dialog... mDialog) {
        for (Dialog dialog : mDialog) {
            controlDialogShow(dialog, activity, false);
        }
    }

}
